package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileuploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

//文件上传
@Slf4j
@RequestMapping("/admin/product")
@RestController
public class FileuploadController {

    @Autowired
    FileuploadService fileuploadService;

    @PostMapping("/fileUpload")
    public Result fileupload(@RequestPart("file") MultipartFile file) throws Exception {

        log.info("接受到文件上传数据：文件名：{}，文件大小：{}",file.getOriginalFilename(),file.getSize());
        //文件上传。
        String path = fileuploadService.upload(file);
        return Result.ok(path);
    }
}
